extends layout

block content
  if errors
    ul.errors
      each error, i in errors
        li.alert-danger #{error.msg}

  form(method='post', action='/api/posts/edit', enctype='multipart/form-data')
    input.form-control(name='id', type='hidden', value=post.id)
    input.form-control(name='previmage', type='hidden', value=post.thumbimage)
    .form-group
      label Title:
      input.form-control(name='title', type='text', value=post.title)
    .form-group
      label Category
      select.form-control(name='category')
        each category, i in categories
          option(value=category.title, selected=(category.id === post.categoryId)? 'selected' : '') #{category.title}
    .form-group
      input(type='hidden', id='body-input', name='content', value=post.content)
      trix-editor(input='body-input')
    .form-group
      label Thumbnail Image
      input.form-control(name='thumbimage', type='file')
      if post.thumbimage
        img(src=post.thumbimage)
    input.btn.btn-default(name='submit', value='Save', type='submit')

    script(src='https://unpkg.com/trix@2.0.8/dist/trix.umd.min.js')
    script
